Crate reqwest_eventsource

Source
Expand description

Provides a simple wrapper for reqwest to provide an Event Source implementation. You can learn more about Server Sent Events (SSE) take a look at the MDN docs This crate uses eventsource_stream to wrap the underlying Bytes stream, and retries failed requests.

ยงExample

โ“˜
let mut es = EventSource::get("http://localhost:8000/events");
while let Some(event) = es.next().await {
    match event {
        Ok(Event::Open) => println!("Connection Open!"),
        Ok(Event::Message(message)) => println!("Message: {:#?}", message),
        Err(err) => {
            println!("Error: {}", err);
            es.close();
        }
    }
}

Modulesยง

retry
Helpers to handle connection delays when receiving errors

Structsยง

CannotCloneRequestError
Error raised when a RequestBuilder cannot be cloned. See RequestBuilder::try_clone for more information
EventSource
Provides the Stream implementation for the Event items. This wraps the RequestBuilder and retries requests when they fail.

Enumsยง

Error
Error raised by the EventSource stream fetching and parsing
Event
Events created by the EventSource
ReadyState
The ready state of an EventSource

Traitsยง

RequestBuilderExt
Provides an easy interface to build an EventSource from a RequestBuilder